import sys, pygame, tile

from tile import *
#constants - basically a list of stuff that gets included by files that need access

#default values
TILESIZE = 16
MAP_WIDTH = 15
MAP_HEIGHT = 15

class ConstantManager:
    """Loads settings from settings.cfg and updates them. If that fails, we fall back on default values."""
    def __init__(self):
        """Initializes the ConstantManager and loads settings."""
        global TILESIZE, MAP_WIDTH, MAP_HEIGHT
        self.settings = {}
        
        try:
            settingsFile = open("settings.cfg", "r")
            content = settingsFile.read()
            settingsFile.close()
            content = content.split("\n")
            keys = []
            values = []

            for item in content:
                item = item.split(":")
                keys.append(item[0])
                values.append(item[1])

            self.settings = dict(zip(keys, values))
            self.settings["SCREENRES"] = [int(self.settings["SCREENRES"].split(",")[0]), int(self.settings["SCREENRES"].split(",")[1])]
            TILESIZE = int(self.settings["TILESIZE"])
            MAP_WIDTH = int(self.settings["MAP_WIDTH"])
            MAP_HEIGHT = int(self.settings["MAP_HEIGHT"])
                                              
        except Exception, message:
            print "Error loading settings: %s" % (message)
            sys.exit()
        
                                           
